package com.waymap.task;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.waymap.common.Constant;
import com.waymap.domain.Transactions;
import com.waymap.mapper.TransactionsMapper;
import com.waymap.utils.mq.MsgProducer;
import org.apache.activemq.command.ActiveMQQueue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.jms.Destination;


@Component
@EnableScheduling
@SuppressWarnings("all")
public class ScheduledTasks {

    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Resource
    private TransactionsMapper transactionsMapper;
    @Autowired
    private MsgProducer producer;

    public final static long FIVE_Minute =  5*60 * 1000;
    /********fixedRate设置为每五分分钟一次，不论你业务执行花费了多少时间,我都是五分钟执行1次************/

    /*@Async
    @Scheduled(fixedRate = FIVE_Minute)
    public void reportCurrentTime() {
        *//*************查找syncToNs为N不成功的推送记录***************//*
        Map<String, Object> param = new HashMap(16);
        param.put("syncToNs","E");
        List<Transactions> tranList =transactionsMapper.getTransactionList(param);
        logger.info("*************定时任务获取Transactions记录条数********************"+tranList.size());
        logger.info("reportCurrentTime name " + Thread.currentThread().getName());
        if(null!=tranList&&tranList.size()>0){
            for(Transactions trs : tranList){
                 logger.info("*************定时任务里准备MQ发送数据********************"+trs.getTranid());
                 Destination destination = new ActiveMQQueue(Constant.Queue_Name);
                 producer.sendMessage(destination, trs.getCreatedFromType() + ":" + trs.getTranid()+":"+trs.getTransactionType()+":"+trs.getAccountId());
                 logger.info("*************定时任务里的MQ发送完成********************");
                 trs.setNum(trs.getNum()+1);
                 transactionsMapper.updateByPrimaryKey(trs);
            }
        }else{
            logger.info("*************定时任务执行记录为0********************");
        }

    }*/
}
